﻿using System.Net.Http;
using CkSoftware.GroupMe.Sdk.Bot.Dao;
using CkSoftware.GroupMe.Sdk.Core;
using CkSoftware.GroupMe.Sdk.Core.Dao;

namespace CkSoftware.GroupMe.Sdk.Bot.Commands
{
	/// <summary>
	/// The create bot command (GroupMe documentation: <see href="https://dev.groupme.com/docs/v3#bots_create" />).
	/// </summary>
	public class CreateBotCommand : IWebApiCommand<GroupMeApiResponse<BotDataResponse>>
	{
		private readonly CreateBotParameters _parameters;

		/// <summary>
		/// Instantiates a new CreateBot command.
		/// </summary>
		/// <param name="botName">The name of the new bot.</param>
		/// <param name="groupId">The group id where the bot should live.</param>
		public CreateBotCommand(string botName, string groupId)
		{
			_parameters = new CreateBotParameters {Bot = new BotData {Name = botName, GroupId = groupId}};
		}

		/// <summary>
		/// The name of the command to be executed.
		/// </summary>
		public string CommandName
		{
			get { return "bots"; }
		}

		/// <summary>
		/// The http method to execute this command.
		/// </summary>
		public HttpMethod HttpMethod
		{
			get { return HttpMethod.Post; }
		}

		/// <summary>
		/// The parameters which should be used on command execution.
		/// </summary>
		public IWebApiCommandParameters Parameters
		{
			get { return _parameters; }
		}

		/// <summary>
		/// Defines if the command is executed once.
		/// </summary>
		public bool CommandExecuted { get; set; }

		/// <summary>
		/// Defines that the bot should contain the given avatar image.
		/// </summary>
		/// <param name="avatarUrl">
		/// The url of the avatar image (must be a GroupMe ImagingService image according to the GroupMe
		/// documentation).
		/// </param>
		/// <returns>The extended CreateBotCommand.</returns>
		public CreateBotCommand WithAvatar(string avatarUrl)
		{
			_parameters.Bot.AvatarUrl = avatarUrl;
			return this;
		}

		/// <summary>
		/// Defines that the bot should have a callback url.
		/// </summary>
		/// <param name="callbackUrl">The callback url where the bot should receive any callbacks.</param>
		/// <returns>The extended CreateBotCommand.</returns>
		public CreateBotCommand WithCallback(string callbackUrl)
		{
			_parameters.Bot.CallbackUrl = callbackUrl;
			return this;
		}
	}
}